#ifndef __FUNC_H__
#define __FUNC_H__

/* Usage: 服务端业务功能函数声明 */

#include <my_header.h>
#include "dir_stack.h"

//缓冲区大小
#define BUF_SIZE 1024
//命令中最多有几个参数
#define MAX_WORDNUM 5
//命令一个参数的最大长度
#define MAX_WORDLEN 30
//外部维护的系统级工作目录
#define ROOTDIR "/home/zyn/user_space/"
//100 MB
#define HUNDRED_MEGABYTE 104857600

typedef enum{
    TAGCD = 1,
    TAGLS,
    TAGREMOVE,
    TAGPWD,
    TAGMKDIR,
    TAGRMDIR,
    TAGGETS,
    TAGPUTS,
    TAG_RESPONSECD,
    TAG_RESPONSELS,
    TAG_RESPONSEREMOVE,
    TAG_RESPONSEPWD,
    TAG_RESPONSEMKDIR,
    TAG_RESPONSERMDIR,
    TAG_RESPONSEGETS,
    TAG_RESPONSEPUTS,

} Tag;


//套接字类型
typedef int socket_t;

//命令类型
typedef struct cmd_s{
    int argc;       //命令中有几个参数
    char cmd[MAX_WORDNUM][MAX_WORDLEN];
} cmd_t, *pcmd_t;

//通讯类型
typedef struct {
	socket_t  _sess_fd ;             //对端套接字
	char _sess_buf[BUF_SIZE] ;  //缓冲区
} Session_t, *pSession_t;

//
typedef struct train_s {
    int tag;
    int data_length;
    char data[BUF_SIZE];
} train_t, *ptrain_t;


void init_cmd(char *line, pcmd_t pcmd); //将line分割，存入cmd
void print_cmd(pcmd_t pcmd); //打印命令
int cmd_check(pcmd_t pcmd);//检查命令是否合法

int handle_path(char *path, char *buf, pdir_stack_t dir_stack);
//执行命令，并向客户端发送命令结果
int do_ls(socket_t fd_client, ptrain_t ptrain, pdir_stack_t dir_stack);
int do_pwd(socket_t fd_client, ptrain_t ptrain, pdir_stack_t dir_stack);
int do_cd(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, pdir_stack_t dir_stack);
int do_rm(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, dir_stack_t dir_stack);
int do_mkdir(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, dir_stack_t dir_stack);
int do_rmdir(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, dir_stack_t dir_stack);
int do_puts(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, dir_stack_t dir_stack);
int do_gets(socket_t fd_client, ptrain_t ptrain, pcmd_t pcmd, dir_stack_t dir_stack);

int get_filesize(char *filename); //获取文件大小
int send_file_train(int fd_client, char *filename); //小于100M的发送方式
int send_file_sendfile(int fd_client, char *filename, off_t filesize); //文件大于100M, 用sendfile发送文件
int recv_file_train(int fd_socket, char *filename); //小于100M的接收方式
int recv_file_mmap(int fd_socket, char *filename, off_t filesize); //大于100M，用mmap接收


#endif


